package Tree116;
import java.util.*;
public class AllTree {
   static class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;
    public TreeNode(int val) {
      this.val = val;
    }
  }

        public boolean isCompleteTree (TreeNode root) {
            // write code here
            if(root==null){
                return true;
            }
            Queue<TreeNode> d1=new LinkedList<>();
            TreeNode cur=root;
            d1.offer(cur);
            int flag=0;
            while(!d1.isEmpty()){
                TreeNode cur2= d1.poll();
                if(cur2.left!=null){
                    if(flag==1){
                        return false;
                    }
                    d1.offer(cur2.left);
                }else{
                    flag=1;
                }
                if(cur2.right!=null){
                    if(flag==1){
                        return false;
                    }
                    d1.offer(cur2.right);
                }else{
                    flag=1;
                }
            }
            return true;
        }
    }
